<template>
	<div class="monitor-2">
		<div>
			<el-date-picker @change='dateChange' v-model="createTime" type="date" :placeholder="$t('route.Select_date')" />
			<div class="div-handle-right">
				<!-- <el-button @click='jumpPage(0)'>添加</el-button> -->
				<!-- <el-button>删除</el-button> -->
				<el-button @click='refreshClick'>{{$t('route.Refresh')}}</el-button>
				<!-- <input placeholder="关键字" /> -->
			</div>
		</div>

		<div>
			<div v-if="chartShow" class="chart" id="echart-1"></div>
		</div>

	</div>
</template>


<script>
	import http from "../../js/http/http.js";
	import api from "../../js/http/api.js";
	import CommonUtils from "../../js/common/common-utils.js";
	import * as echarts from 'echarts';
	import i18n from '../../i18n/index';
	import {
		markRaw
	} from 'vue'
	export default {
		data() {
			return {
				device: null,
				createTime: new Date(),
				chartShow: false
			};
		},
		methods: {
			getSewStepReport() {
				http.post(api.GET_SEW_STEP_REPORT, {
					deviceId: this.device.id,
					createTime: this.createTime.format('yyyy-MM-dd')
				}, data => {
					var xData = [];
					var yData = [];
					for (var i = 0; i < data.data.length; i++) {
						xData.push(i + 's');
						yData.push(data.data[i]);
					}
					this.initEchart1(xData, yData);
				});
			},

			dateChange() {
				this.getSewStepReport();
			},

			initEchart1(xData, yData) {
				var myChart = markRaw(echarts.init(document.getElementById("echart-1")));
				var option = CommonUtils.initStepLineChartOption(i18n.global.t('route.Sewing_curve'), xData, yData);
				myChart.setOption(option);
			},
			refreshClick() {
				this.getSewStepReport();
			}
		},
		created() {

		},
		mounted() {
			this.chartShow = true;
			this.device = JSON.parse(this.$route.params.device);
			this.getSewStepReport();
		},
		destroyed() {
			this.chartShow = false;
			console.log("======destroyed====")
		}
	};
</script>

<style lang="scss" scoped>
	.monitor-2 {
		>div:nth-of-type(1) {
			display: flex;
			flex-direction: row;
			align-items: center;
			margin-top: 20px;
			background-color: #ffffff;
			padding: 20px;
			border-radius: 5px;

			.div-handle-right {
				flex: 1;
				flex-direction: row-reverse;
				text-align: right;
				display: flex;
				align-items: center;

				>input:nth-of-type(1) {
					border: 1px solid #eeeeee;
					font-size: 15px;
					width: 150px;
					padding: 5px 8px;
					outline: none;
				}

				>button {
					color: #A866FF;
					margin-left: 10px;
					padding: 4px 20px;
				}
			}
		}

		>div:nth-of-type(2) {
			background-color: #ffffff;
			padding: 20px;
			border-radius: 5px;

			.chart {
				height: 250px;
				width: 100%;

			}
		}


	}
</style>
